#!/usr/local/bin/python2.4

from wsgiref.handlers import CGIHandler
import wlpages

#wlpages.DEBUG = True
wlpages.CACHE = False

class PathinfoMiddleware:
    ''' Make sure 'PATH_INFO' exists and add it if not. '''

    def __init__(self, app):
        self.app = app

    def __call__(self, environ, start_response):
        ''' Add 'PATH_INFO' if missing and return app. '''
        if not environ.get('PATH_INFO'):
	        environ['PATH_INFO'] = environ.get('REQUEST_URI', \
                                   environ.get('SCRIPT_URL', '/'))
        return self.app(environ, start_response)

app = PathinfoMiddleware(wlpages.wlpages)
CGIHandler().run(app)
